// pages/order/list/index.js
import { getOrderListApi } from '../../../api/orderPay'
Page({
  // 页面的初始数据
  data: {
    orderList: [],
    page: '1',
    limit: '10',
    total: 0,
    isLoading: false // 判断数据是否记载完毕
  },
  async getOrderList() {
    const { page, limit } = this.data
    const res = await getOrderListApi(page, limit)
    console.log(res.data.records)
    this.setData({
      orderList: [...this.data.orderList, ...res.data.records],
      total: res.data.total
    })
  },
  onReachBottom() {
    // 解构数据
    const { page, total, orderList } = this.data
    if (isLoading) return
    if (total === orderList.length) {
      return wx.toast({ title: '数据加载完毕' })
    }
    // 更新 page
    this.setData({
      page: page + 1
    })

    // 重新发送请求
    this.getOrderList()
  },
  onLoad() {
    this.getOrderList()
  }
})
